package com.luoying.itew.dialog;

import android.app.Dialog;
import android.content.Context;
import androidx.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.luoying.itew.R;

/**
 * Created by lufan on 2018/12/6
 * Class describe
 */
public class UpdateVersionDialog extends Dialog {
    private Button cancalBtn,okBtn;
    private VersionDialogListener onClickListener;

    public UpdateVersionDialog(@NonNull Context context) {
        super(context,R.style.ConfirmFrameWindowStyle);
        setContentView(R.layout.dialog_update);
        Window window = this.getWindow();
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.gravity = Gravity.CENTER;
        this.onWindowAttributesChanged(wl);
        this.setCanceledOnTouchOutside(false);
        cancalBtn = findViewById(R.id.btn_dialog_cancel);
        okBtn = findViewById(R.id.btn_dialog_ok);
        cancalBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener!=null){
                    onClickListener.cancalClick();
                }
            }
        });
        okBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onClickListener!=null){
                    onClickListener.okClick();
                }
            }
        });
    }

    /**
     * 是否强制更新
     * @param b
     */
    public void isForcde(boolean b) {
        if(b){
            cancalBtn.setVisibility(View.GONE);
        }
    }

    public void setOnClickListener(VersionDialogListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface VersionDialogListener {
        void cancalClick();
        void okClick();
    }
}
